<template>
  <!-- 2.准备一个具备宽高的容器 -->
  <div class="LineChart-container" ref="chartRef"></div>
</template>

<script lang="ts">
export default {
  name: "LineChart",
};
</script>

<script lang="ts" setup>
// 1.引入echarts
import * as echarts from "echarts";
import { onMounted, ref } from "vue";

const chartRef = ref();

onMounted(() => {
  // 3.初始化echarts实例
  const myEcharts = echarts.init(chartRef.value);
  // 4.定义图标选项
  const option = {
    xAxis: {
      data: [
        "一月",
        "二月",
        "三月",
        "四月",
        "五月",
        "六月",
        "七月",
        "八月",
        "九月",
        "十月",
        "十一月",
        "一二月",
      ],
      // 坐标轴两边不留白
      boundaryGap: false,
    },
    yAxis: {
      show: false, //y轴隐藏
    },
    series: {
      type: "line",
      data: [22, 15, 33, 36, 36, 29, 32, 23, 35, 29, 18, 26],
      // 拐点样式
      itemStyle: {
        opacity: 0,
      },
      // 显示曲线
      smooth: true,
      // 区域颜色
      areaStyle: {
        color: "#a64ca6",
        opacity: 1,
      },
      // 线样式
      lineStyle: {
        color: "#a64ca6",
      },
    },
    grid: {
      left: 0,
      right: 0,
      top: 0,
      bottom: 0,
    },
  };
  // 5.渲染图标
  myEcharts.setOption(option);
});
</script>

<style scoped>
.LineChart-container {
  height: 100%;
}
</style>
